﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.IO;
using Utility;
//using Utility;
using LiquidMeasure.Properties;

namespace LiquidMeasure
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        CalibrationWindow calibWindow;

        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length < 1)
            {
                MessageBox.Show("缺少命令行参数！");
                return;
            }

            
            string sInitWindow = e.Args[0];
            switch (sInitWindow.ToLower())
            {
                case "c":
                    calibWindow = new CalibrationWindow();
                    GlobalVals.sCalibFile = Calib.GetCalibFolder() + "default.xml";
                    calibWindow.ShowDialog();
                    break;
                case "m":
                    if (e.Args.Length != 2)
                    {
                        MessageBox.Show("测量模式没有指定配置文件！");
                        return;
                    }

                    GlobalVals.curBatch = 1;
                    string sSampleCountPerGrid = ConfigurationManager.AppSettings[stringRes.sampleCountPerGrid];
                    GlobalVals.maxSamplesPerBatch = int.Parse(sSampleCountPerGrid);

                    string sCalib = e.Args[1] + ".xml";
                    sCalib = Calib.GetCalibFolder() + sCalib;
                    if (!File.Exists(sCalib))
                    {
                        MessageBox.Show("找不到配置文件!");
                        return;
                    }
                    GlobalVals.sCalibFile = sCalib;
                    Calib.Instance.Write2ROI4Cpp();
                    MainWindow mainWindow = new MainWindow();
                    bool res = (bool)mainWindow.ShowDialog();
                    Application.Current.Shutdown(res?1:0);
                    break;
            }
        }
    }

    
}
